package com.example.administrator.swredeem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.swredeem.R;
import com.example.administrator.swredeem.beanClass.UserListBean;
import com.google.gson.Gson;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UserDataActivity extends AppCompatActivity {

    String title = null;
    String elementsBeanjson = null;
    LinearLayout layoutkh, layoutbk;
    UserListBean.InfoBean elementsBean;
    @BindView(R.id.user_huhao)
    TextView userHuhao;
    @BindView(R.id.user_name)
    TextView userName;
    @BindView(R.id.user_type)
    TextView userType;
    @BindView(R.id.user_IDCrad)
    TextView userIDCrad;
    @BindView(R.id.user_addr)
    TextView userAddr;
    @BindView(R.id.user_bh)
    TextView userBh;
    @BindView(R.id.user_bj_type)
    TextView userBjType;
    @BindView(R.id.user_ICCrad)
    TextView userICCrad;
    @BindView(R.id.user_gqcs)
    TextView userGqcs;
    @BindView(R.id.user_gqzl)
    TextView userGqzl;
    @BindView(R.id.user_kh_bh)
    TextView userKhBh;
    @BindView(R.id.user_kh_bjType)
    TextView userKhBjType;
    @BindView(R.id.user_kh_bcj)
    TextView userKhBcj;
    @BindView(R.id.user_kh_bxh)
    TextView userKhBxh;
    @BindView(R.id.user_kh_bx)
    TextView userKhBx;
    @BindView(R.id.Go_gqfk)
    Button GoGqfk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_data);
        ButterKnife.bind(this);
        title = getIntent().getStringExtra("title");
        elementsBeanjson = getIntent().getStringExtra("elementsBean");

        layoutkh = findViewById(R.id.iskaihu);
        layoutbk = findViewById(R.id.isbuka);
        layoutkh.setVisibility(View.GONE);
        layoutbk.setVisibility(View.GONE);
        if (title.equals("开卡")) {
            layoutkh.setVisibility(View.VISIBLE);
        } else if (title.equals("补卡")) {
            layoutbk.setVisibility(View.VISIBLE);
        }

        init();
    }

    private void init() {
        Gson gson = new Gson();
        elementsBean = gson.fromJson(elementsBeanjson, UserListBean.InfoBean.class);
        userHuhao.setText("表号:" + elementsBean.getUserid());
        userName.setText("姓名:" + elementsBean.getUsername());
        userType.setText("用户类型:" + elementsBean.getUsertype());
        userIDCrad.setText("证件号码:" + elementsBean.getCertnum());
        userAddr.setText("地址:" + elementsBean.getAddr());
        userKhBh.setText("表号:" + elementsBean.getResid());
        userKhBjType.setText("表具类型:" + elementsBean.getRestype());
        userKhBcj.setText("表厂家:" + elementsBean.getFactory());
        userKhBxh.setText("表型号:" + elementsBean.getModelid());
//        userKhBx.setText("表向:"+elementsBean.getMeterdirect()+"");

        if (!TextUtils.isEmpty((String) elementsBean.getMeterdirect())) {
            if (elementsBean.getMeterdirect().equals("L")) {
                userKhBx.setText("表向:左");
            } else if (elementsBean.getMeterdirect().equals("R")) {
                userKhBx.setText("表向:右");
            } else {
                userKhBx.setText("表向:无");
            }
        } else {
            userKhBx.setText("表向:无");
        }

//        userType.setText(elementsBean.get);
    }

    public void goTobuygas(View v) {
        Intent intent = new Intent(UserDataActivity.this, TobuygasActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("userid", elementsBean.getUserid());
        intent.putExtra("factory", elementsBean.getFactory());
        startActivity(intent);
    }


}
